View Javadoc

1   // Copyright (C) 2004, Brian Enigma <enigma at netninja.com>
2   // This file is part of Mac-Package.
3   //
4   // Mac-Package is free software; you can redistribute it and/or modify
5   // it under the terms of the GNU General Public License as published by
6   // the Free Software Foundation; either version 2 of the License, or
7   // (at your option) any later version.
8   //
9   // Mac-Package is distributed in the hope that it will be useful,
10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  // GNU General Public License for more details.
13  //
14  // You should have received a copy of the GNU General Public License
15  // along with Foobar; if not, write to the Free Software
16  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  package org.ninjasoft.macpackager;
18  
19  import java.io.*;
20  import java.util.*;
21  import org.apache.tools.ant.*;
22  import org.apache.tools.ant.types.FileSet;
23  
24  /***
25   * Ant task that will create a Mac OS X application bundle.
26   * This task expects a nested fileset of *.jar files
27   * 
28   * Requires: jar files (in nested fileset)
29   *           BundleName - Name of application
30   *           Version - Application version
31   *           InfoString - Name, version, copyright information
32   *           Icon file - *.icns file containing application icon(s)
33   *           VM Options - Optional things to pass to the VM (name in app menu, shiny metal look, etc)
34   *           mainclass - main class
35   *  
36   * Derives:  BundleIdentifier: from mainclass + version
37   *           
38   * @author Brian Enigma
39   */
40  public AntMacPackager extends Task {/package-summary.html">class AntMacPackager extends Task {
41      privateMacPackager macPackager = new MacPackager()/package-summary.html">ong> MacPackager macPackager = new MacPackager();
42      protected Vector filesets = new Vector();
43      
44      private void loadNestedFileSets() {
45          for (Iterator i = this.filesets.iterator(); i.hasNext(); ) {
46              FileSet fileset = (FileSet) i.next();
47              DirectoryScanner scanner = null;
48              scanner = fileset.getDirectoryScanner(getProject());
49              File fromDir = fileset.getDir(getProject());
50              String[] srcFiles = scanner.getIncludedFiles();
51              for (int j=0; j<srcFiles.length; j++)
52                  macPackager.addJar(fromDir + "/" + srcFiles[j]);
53          }
54      }
55      
56      public void execute() throws BuildException {
57          // Sanity-check the input
58          loadNestedFileSets();
59          try{
60          	macPackager.buildApplication();
61          }catchPackageException e){/package-summary.html">rong>(PackageException e){
62              throw new BuildException(e);
63          }
64      }
65      
66      // #####################################################################
67      // Setters
68      public void addFileset(FileSet fileset) {
69          this.filesets.add(fileset);
70      }
71      
72  	public void setIcon(String icon) {
73          macPackager.setIcon(icon);
74  	}
75  	public void setInfoString(String infoString) {
76          macPackager.setInfoString(infoString);
77  	}
78  	public void setMainClass(String mainClass) {
79          macPackager.setMainClass(mainClass);
80  	}
81  	public void setVersion(String version) {
82          macPackager.setVersion(version);
83  	}
84  	public void setVmOptions(String vmOptions) {
85          macPackager.setVmOptions(vmOptions);
86  	}
87  	public void setAppName(String appName) {
88          macPackager.setAppName(appName);
89  	}
90  }